﻿<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Unique Value Renderer</title>
     <link rel="stylesheet" type="text/css" href="http://localhost:8080/testA/arcgisjs/js/dojo/dijit/themes/tundra/tundra.css" />
    <script type="text/javascript" src="http://localhost:8080/testA/arcgisjs/init.js"></script>
    <script type="text/javascript" src="http://localhost:8080/testA/arcgisjs/jsapi_vsdoc12_v38.js"></script>
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/testA/arcgisjs/js/esri/css/esri.css" />
    <style>
      html, body, #map{
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <script>
        var map;
        require([
          "esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate",
          "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
          "esri/renderers/UniqueValueRenderer", "esri/Color",
          "dojo/domReady!"
        ], function (
          Map, FeatureLayer, InfoTemplate,
          SimpleLineSymbol, SimpleFillSymbol,
          UniqueValueRenderer, Color
        ) {
            map = new Map("map", {
                basemap: "streets",
                center: [-95.625, 39.243],
                zoom: 4,
                slider: false
            });
            map.on("load", addFeatureLayer);

            function addFeatureLayer() { 
                var defaultSymbol = new SimpleFillSymbol().setStyle(SimpleFillSymbol.STYLE_NULL);
                defaultSymbol.outline.setStyle(SimpleLineSymbol.STYLE_NULL);

                //create renderer
                var renderer = new UniqueValueRenderer(defaultSymbol, "SUB_REGION");

                //为每个值添加符号
                renderer.addValue("Pacific", new SimpleFillSymbol().setColor(new Color([255, 0, 0, 0.5])));
                renderer.addValue("Mtn", new SimpleFillSymbol().setColor(new Color([0, 255, 0, 0.5])));
                renderer.addValue("N Eng", new SimpleFillSymbol().setColor(new Color([0, 0, 255, 0.5])));
                renderer.addValue("S Atl", new SimpleFillSymbol().setColor(new Color([255, 0, 255, 0.5])));
                renderer.addValue("Mid Atl", new SimpleFillSymbol().setColor(new Color([255, 255, 255, 0.75])));
                renderer.addValue("E N Cen", new SimpleFillSymbol().setColor(new Color([0, 255, 255, 0.5])));
                renderer.addValue("W N Cen", new SimpleFillSymbol().setColor(new Color([255, 255, 0, 0.5])));
                renderer.addValue("E S Cen", new SimpleFillSymbol().setColor(new Color([127, 127, 127, 0.5])));
                renderer.addValue("W S Cen", new SimpleFillSymbol().setColor(new Color([0, 0, 0, 0.5])));

                var featureLayer = new FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1", {
                    infoTemplate: new InfoTemplate(" ", "${SUB_REGION}"),
                    mode: FeatureLayer.MODE_ONDEMAND,
                    outFields: ["SUB_REGION"]
                });

                featureLayer.setRenderer(renderer);
                map.addLayer(featureLayer);
            }
        });
    </script>
  </head>
  
  <body>
    <div id="map"></div>
  </body>

</html>